﻿namespace BM.Tools.WebControls.MForm.Controls.Helper
{
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    /// <summary>
    /// The input that keeps information about the owner control on the client side
    /// </summary>
    [System.ComponentModel.DesignTimeVisible(false)]
    public class HiddenInput : HtmlInputHidden
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HiddenInput"/> class. 
        /// </summary>
        /// <param name="ownerControl">
        /// The ownerControl.
        /// </param>
        public HiddenInput(Control ownerControl)
        {
            Owner = ownerControl;
        }

        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        /// <value>
        /// The html name attribute.
        /// </value>
        public override string Name
        {
            get
            {
                return Owner.ClientID;
            }

            set
            {
                base.Name = value;
            }
        }

        /// <summary>
        /// Gets Owner.
        /// </summary>
        /// <value>
        /// The owner.
        /// </value>
        public Control Owner
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets Value.
        /// </summary>
        /// <value>
        /// The value.
        /// </value>
        public override string Value
        {
            get
            {
                if (Page.IsPostBack)
                {
                    return Page.Request[Owner.ClientID];
                }

                return base.Value;
            }

            set
            {
                base.Value = value;
            }
        }
    }
}